package hibernate.modelConverter;

import hibernate.model.Sirketprofil;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("SirketConverter")
public class SirketConverter implements Converter{

	@Override
	public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
			System.out.println("Sirket-3");
			if(!value.equals("")){
				System.out.println("value ="+ value);
				Sirketprofil srfprf = new Sirketprofil();
				srfprf.setFirmaid((Long.parseLong(value.trim())));
				System.out.println("malibu : "+srfprf.getFirmaAd());
				return srfprf;
			}
			System.out.println("Sirket-4");
			return null; // **** alternative with return null; ****
	}
	
	@Override
	public String getAsString(FacesContext fc, UIComponent uic, Object value) {
		if (value == null || value.equals("")) {
			System.out.println("Sirket-1");
			return "";
		} else {
			Sirketprofil srfprf = (Sirketprofil) value;
			System.out.println("Sirket-2 ve id " + srfprf.getFirmaid());			
			return ""+srfprf.getFirmaid();
		}
	}
}